<?php
require_once('../lib/standard.php');
require_once('../lib/notes.php');
set_pineza();

// Ελέγχουμε αν έχουν δοθεί όλα στοιχεία που απαιτούνται για
// τη δημιουργία λογαριασμού.

if ((!perastike('login')) || (!$_REQUEST['login'])) telos('no login name passed');
else $login = $_REQUEST['login'];

if ((!perastike('onoma')) || (!$_REQUEST['onoma'])) telos('no user name passed');
else $onoma = "'" . escape($_REQUEST['onoma']) . "'";

if ((!perastike('email')) || (!$_REQUEST['email'])) $email = 'NULL';
else $email = "'" . escape($_REQUEST['email']) . "'";

if ((!perastike('kodikos')) || (!$_REQUEST['kodikos'])) $kodikos = '';
else $kodikos = "'" . escape(sha1($_REQUEST['kodikos'])) . "'";

if (perastike('when') && $_REQUEST['when']) {
	$when_col = ', `date`';
	$when_val = ", '{$_REQUEST['when']}'";
}
else {
	$when_col = '';
	$when_val = '';
}

// Δημιουργούμε τώρα το λογαριασμό εισάγοντας τα στοιχεία του χρήστη
// στην database.

mysqli_autocommit($pineza->db, FALSE);
$query = "INSERT INTO `user` (`login`, `name`, `email`, `password`{$when_col}) " .
	"VALUES ('" . escape($login) . "', {$onoma}, {$email}, {$kodikos}{$when_val})";
if ((!mysqli_query($pineza->db, $query)) || (mysqli_affected_rows($pineza->db) != 1))
	akiro('account creation failed (' . mysqli_error($pineza->db) . ')');

insert_board($login, '', 'My draft board');
insert_board($login, 'GREEN', 'My green board');
insert_board($login, 'INDIAN', 'My indian board');
insert_board($login, 'NEUTRAL', 'My neutral board');
insert_board($login, 'TEAL', 'My teal board');
insert_board($login, 'PAPER', 'My paper board');
insert_board($login, 'LILA', 'My violette board');
insert_board($login, 'RED', 'My red board');
insert_board($login, 'TRASH', '');

$font = 'Comic Sans MS, cursive, serif';
new_note($login, '', "<h1>Welcome {$login}!</h1>" .
	"Too many jobs to be done? " .
	"Can't remember what you have to do? You are at the right place!",
	$font, 'B8DB4D', FALSE, 'HIGH');
new_note($login, '', "<h1>Divide et impera!</h1>A variety of boards is at your service. " .
	"It's in your choice to stick your notes all together, " .
	"or split them up in manageable groups!",
	$font, 'FFFF33');
new_note($login, '', "<h1>Color your jobs!</h1>You can choose colors from " .
	"the rich RGB color suit. You can also choose fonts, or you can " .
	"embed HTML tags in your notes. It's all up to you!",
	$font, 'FF66A3');
new_note($login, '', '<span style="color: #FFCC00;"><h1>New note?</h1>' .
	'<img title="new note" onclick="neoSimioma(this);" src="' . $pineza->server .
	'images/note.gif" alt="new note icon" style="width: 1.2cm; float: left;"/>' .
	'<div>To post a new note, just click the small note ' .
	'icon at the tool bar and fill the form.</div></span>',
	$font, '336699');
new_note($login, '', '<h1>Move notes?</h1>' .
	'To move notes between boards ' .
	'click the pins of the notes to be moved and then click the ' .
	'target board at the sidebar.',
	$font, 'FFFFA3');
new_note($login, '', "<h1>Delete notes</h1>To delete notes, just move " .
	"them to the trash. Click the trash board whenever you decide " .
	"to empty the trash.",
	$font, 'A3FFA3');
new_note($login, '', "<h1>Edit notes</h1>You can edit a note, change " .
	"its color or font, by double clicking on the note's body.",
	$font, 'FF8080');
new_note($login, '', "<h1>Rename your boards!</h1>You can rename your boards " .
	"by double clicking on the current board names at the sidebar.",
	$font, '99D6D6');
new_note($login, '', "<h1>Small, medium, large!</h1>Clicking on the note " .
	"will change the size from small to wide and, finally, big and so forth. " .
	"Click here to see how it works and read farther. Not just to fit content, " .
	"but attract your attention too! Click again to maximize that note.<br /><hr />" .
	'Brian W. Kernighan says: <span style="font-style: italic; color: #FF3300;">' .
	"It is twice as difficult to debug a program as " .
	"to write it. Therefore, if you put all of your creativity and effort into " .
	"writing the program, you will not be smart enough to debug it.</span>" .
	"<br /><hr />You can always restore normal note size by clicking once more. " .
	"There are also available resizing handlers at the right edge, low edge, " .
	"and low-right corner of every note.",
	$font, '99FF66');
new_note($login, '', "<h1>Mail your notes!</h1>You can mail your notes to anybody, " .
	"including yourself.",
	$font, 'FFCCCC');

// Μόλις έχει δημιουργηθεί ο λογαριασμός, οπότε θέτουμε τον τρέχοντα χρήστη
// στον αντίστοιχο χρήστη.

if (mysqli_commit($pineza->db))
	$_SESSION['login'] = $login;

$pineza->close_database();
print AJAX_SEP;
?>
